#pragma once

#include "Include.h"
#include "GomokuBoard.h"
#include "ThreatSpaceCoordinateGetters.h"

typedef enum {THREAT_FIVE, THREAT_FOUR_STRAIGHT, THREAT_FOUR, THREAT_THREE} ThreatType;

class Threat
{
public:
	ThreatType m_type;
	Move m_gainSquare;
	std::list<int*> m_costSquares;

	~Threat()
	{
		for(std::list<int*>::iterator it = m_costSquares.begin(); it != m_costSquares.end(); it++)
		{
			//delete *it;
			it = m_costSquares.erase(it);
			if(it == m_costSquares.end()) break;
		}
	}

	void Print(std::ostream &stream);

	void Write(std::ostream &stream);
	void Parse(std::istream &stream);
};

bool ThreatCompare(Threat threat0, Threat threat1);

void SaveThreatReference(std::string name);
void LoadThreatReference(std::string name);
void AddThreatReference(Board board, std::list<Threat> threats);
bool SearchThreatReference(Board board, std::list<Threat> &threats);

void FindAllThreats(int player, Board board, std::list<Threat> &threats);
void FindThreats(CoordinateGetter &getter, int player, Board board, std::list<Threat> &threats);
int FindThreatSequence(int player, Board board, std::list<Threat> threats, int depth, Move &out);
bool CounterOpponentThreat(int player, Board board, std::list<Threat> opponentThreats, Move &out);